
var ExportSheet = require('./ExportSheet');
const ExportDir = require("./ExportDir");
const ExportHead = require("./ExportHead");
const ExportManager = require('./ExportManager')

const ClientExport = require('./ClientExport')
const Define = require('./ExportDefine')
var coder = require('../public/coder')
var file_util = require('../public/file_util');
const path = require('path');
//每个文件的处理类
function ExportExcel(list, export_dir, configObj) {
    this.list = list;
    this.export_dir = export_dir;
    this.sheetList = [];
    this.sheetMap = {}
    this.sheetMap[Define.CLIENT_TYPE] = []
    this.sheetMap[Define.SERVER_TYPE] = []
    this.configObj = configObj;
    this.dir = new ExportDir(this.export_dir)
    if (this.list.length > 0) {
        var headConfig = this.list[0].data;
        this.head = new ExportHead(headConfig)
    }
    // this.manager = new ExportManager(this.list, this.head.headConfig, this.dir.class_path)
    this.clientExport = new ClientExport(configObj);
}

ExportExcel.prototype.export = function (managerTemplate, template) {
    if (!this.head) {
        return;
    }

    for (var i = 1; i < this.list.length; i++) {
        if (!this.head.headConfig[i]) {
            continue;
        }
        let sheet = new ExportSheet(i, this.list[i], this.head, this.dir, Define.CLIENT_TYPE)
        if (sheet.isOk()) {
            sheet.parseEnum()
            sheet.parseData();
            this.sheetList.push(sheet)
            this.sheetMap[Define.CLIENT_TYPE].push(sheet)

            sheet = new ExportSheet(i, this.list[i], this.head, this.dir, Define.SERVER_TYPE)
            sheet.parseEnum()
            sheet.parseData();
            this.sheetMap[Define.SERVER_TYPE].push(sheet)
        }

    }

    this.clientExport.export(this.sheetMap[Define.CLIENT_TYPE], this.head, this.dir)

}

ExportExcel.prototype.getSheetList = function(type){
    return this.sheetMap[type];
}
module.exports = ExportExcel; 